﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AnesSystem.ViewModels;
using AnesSystem.Models;

namespace AnesSystem.Controls
{
    /// <summary>
    /// AnesMethodsCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class AnesMethodsWin : Window
    {

        #region Variables
        private AnesMethodsCtrlViewModel _model;
        private string _methodOneString;

        #endregion

        #region Constructor
        public AnesMethodsWin()
        {
            InitializeComponent();
            _model = new AnesMethodsCtrlViewModel();
            this.DataContext = _model;
            SelectDefault();

        }

        private void SelectDefault()
        {
            if (_model.OneMethodIndex!=-1)
            {
                _model.CheckChangedTwo(_model.OneMethodIndex);
            }
           
        }

        #endregion

        #region Properties

        /// <summary>
        /// 麻醉方式全名
        /// </summary>
        public string MethodFullName { get; set; }

        #endregion

        #region 依赖属性

        #endregion

        #region Event

        #endregion

        #region Private Methods

        #endregion

        #region Public/Protected Methods

        #endregion

        #region EventHandlers

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            CloseWin();
        }
        private void CloseWin()
        {
            MethodFullName = _model.AnesMethodFullName;
            this.Close();
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox ctrl = sender as CheckBox;
            int id = (ctrl.DataContext as ConfigAnesMethodItem).ConfigAnesMethod.Index;
            string methodTwoString = (ctrl.DataContext as ConfigAnesMethodItem).ConfigAnesMethod.Name;
            _model.CheckChanged(id);
            _model.MethodTwoString = methodTwoString;
            CloseWin();

        }
        private void unCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            CheckBox ctrl = sender as CheckBox;
            int id = (ctrl.DataContext as ConfigAnesMethodItem).ConfigAnesMethod.Index;
            string methodTwoString = (ctrl.DataContext as ConfigAnesMethodItem).ConfigAnesMethod.Name;
            _model.unCheckChanged(id);
            _model.MethodTwoString = "";
          
        }
        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            TextBlock ctrl = sender as TextBlock;
            _methodOneString = ctrl.Text;
            _model.MethodOneString = _methodOneString;
            int id = (ctrl.DataContext as ConfigAnesMethodItem).ConfigAnesMethod.Index;
            _model.CheckChangedTwo(id);
        }

        private void CheckBox_Checked1(object sender, RoutedEventArgs e)
        {
            CheckBox checkbox = sender as CheckBox;
            string name =(string) checkbox.Content;
            if (name.Equals("无麻醉"))
            {
                _model.AnesMethodFullName = "无麻醉";
            }
            if (name.Equals("静脉麻醉"))
            {
                _model.AnesMethodFullName = "静脉麻醉";
            }
            if (name.Equals("非插管全麻"))
            {
                _model.AnesMethodFullName = "非插管全麻";
            }
            CloseWin();

        }

        private void unCheckBox_Unchecked1(object sender, RoutedEventArgs e)
        {
            CheckBox checkbox = sender as CheckBox;
            string name = checkbox.Name;
            _model.AnesMethodFullName = "";

        }

        #endregion



    }
}
